package net.cloudcodex.client.storyboard.cdo;

/**
 * Unique key to identify a character of a campaign.
 * 
 * @author ADaroussin
 */
public class CharacterKeyCDO implements Comparable<CharacterKeyCDO> {
	private final long campaignId;
	private final long characterId;

	public CharacterKeyCDO(long campaignId, long characterId) {
		this.campaignId = campaignId;
		this.characterId = characterId;
	}

	public long getCampaignId() {
		return campaignId;
	}

	public long getCharacterId() {
		return characterId;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (campaignId ^ (campaignId >>> 32));
		result = prime * result + (int) (characterId ^ (characterId >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		CharacterKeyCDO other = (CharacterKeyCDO) obj;
		if (campaignId != other.campaignId) {
			return false;
		}
		if (characterId != other.characterId) {
			return false;
		}
		return true;
	}

	@Override
	public int compareTo(CharacterKeyCDO o) {
		final int compare = ((Long) this.campaignId).compareTo(o.getCampaignId());
		if (compare != 0) {
			return compare;
		}
		return ((Long) this.characterId).compareTo(o.getCharacterId());
	}
}
